<template>
  <div class="profile-container">
    <!-- 顶部个人信息卡片 -->
    <div class="profile-banner student-banner">
      <div class="banner-overlay"></div>
      <div class="profile-header">
        <div class="profile-header-content">
          <div class="avatar-wrapper">
            <div class="avatar-container">
              <el-avatar :size="100" :icon="UserFilled" class="user-avatar" src="https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png" />
              <div class="avatar-badge student-badge">
                {{ roleText }}
              </div>
            </div>
          </div>
          <div class="user-info">
            <h1>{{ userInfo.name }}</h1>
            <p>{{ userInfo.department }}</p>
            <div class="user-tags">
              <el-tag type="success" effect="plain" class="sync-badge" size="large">
                <el-icon><RefreshRight /></el-icon>
                教务系统实时同步
              </el-tag>
              <el-tag type="info" effect="plain" size="large">
                <el-icon><School /></el-icon>
                {{ userInfo.grade }}
              </el-tag>
            </div>
          </div>
        </div>
      </div>
    </div>

    <!-- 内容区域 -->
    <div class="profile-tabs">
      <el-tabs v-model="activeTab" type="border-card" class="custom-tabs">
        <!-- 学生信息展示 -->
        <el-tab-pane name="basic">
          <template #label>
            <div class="custom-tab-label">
              <el-icon><UserFilled /></el-icon>
              <span>基本信息</span>
            </div>
          </template>
          <div class="tab-content">
            <el-card class="info-card" shadow="hover">
              <div class="info-header">
                <h3>个人基本信息</h3>
                <p>您的基本身份信息</p>
              </div>
              <el-descriptions :column="2" border size="large" class="custom-descriptions">
                <el-descriptions-item label="姓名" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.name }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="学号" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.studentId }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="性别" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.gender }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="院系" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.department }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="专业" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.major }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="班级" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.className }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="年级" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.grade }}</span>
                </el-descriptions-item>
              </el-descriptions>
            </el-card>
          </div>
        </el-tab-pane>

        <el-tab-pane name="academic">
          <template #label>
            <div class="custom-tab-label">
              <el-icon><School /></el-icon>
              <span>学籍信息</span>
            </div>
          </template>
          <div class="tab-content">
            <el-card class="info-card" shadow="hover">
              <div class="info-header">
                <h3>学籍档案信息</h3>
                <p>您的学籍相关信息</p>
              </div>
              <el-descriptions :column="2" border size="large" class="custom-descriptions">
                <el-descriptions-item label="入学日期" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.enrollmentDate }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="学制" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.schoolingLength }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="培养层次" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.educationLevel }}</span>
                </el-descriptions-item>
              </el-descriptions>
              <div class="info-extra">
                <el-alert
                  title="学籍信息由教务系统维护，如有问题请联系教务处"
                  type="info"
                  :closable="false"
                  show-icon
                />
              </div>
            </el-card>
          </div>
        </el-tab-pane>

        <el-tab-pane name="contact">
          <template #label>
            <div class="custom-tab-label">
              <el-icon><Message /></el-icon>
              <span>联系信息</span>
            </div>
          </template>
          <div class="tab-content">
            <el-card class="info-card" shadow="hover">
              <div class="info-header">
                <h3>联系方式</h3>
                <p>您的联系信息（部分信息已脱敏处理）</p>
              </div>
              <el-descriptions :column="2" border size="large" class="custom-descriptions">
                <el-descriptions-item label="邮箱" label-class-name="label-bold">
                  <span class="info-value">{{ userInfo.email }}</span>
                </el-descriptions-item>
                <el-descriptions-item label="手机号" label-class-name="label-bold">
                  <div class="sensitive-field">
                    <span class="info-value">{{ maskSensitiveInfo(userInfo.phone) }}</span>
                    <el-tooltip content="敏感信息已脱敏显示" placement="top">
                      <el-icon class="sensitive-icon"><Lock /></el-icon>
                    </el-tooltip>
                  </div>
                </el-descriptions-item>
                <el-descriptions-item label="紧急联系人电话" label-class-name="label-bold">
                  <div class="sensitive-field">
                    <span class="info-value">{{ maskSensitiveInfo(userInfo.emergencyContact) }}</span>
                    <el-tooltip content="敏感信息已脱敏显示" placement="top">
                      <el-icon class="sensitive-icon"><Lock /></el-icon>
                    </el-tooltip>
                  </div>
                </el-descriptions-item>
              </el-descriptions>
              <div class="info-extra">
                <el-alert
                  title="请确保您的联系方式保持最新，以便学校能够及时与您联系"
                  type="warning"
                  :closable="false"
                  show-icon
                />
              </div>
            </el-card>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>

    <!-- 底部操作区域 -->
    <div class="profile-actions">
      <el-card shadow="hover" class="action-card">
        <div class="action-header">
          <h3>操作中心</h3>
        </div>
        <div class="action-content">
          <el-button type="primary" :icon="Edit">修改个人信息</el-button>
          <el-button type="warning" :icon="Key">修改密码</el-button>
          <el-button type="success" :icon="Document">申请成绩单</el-button>
          <el-button type="info" :icon="Download">下载学籍卡片</el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { UserFilled, RefreshRight, Message, School, Lock, Edit, Key, Document, Download } from '@element-plus/icons-vue'

const route = useRoute()

// 角色文本显示
const roleText = '学生'

// 添加activeTab状态来控制当前激活的标签页
const activeTab = ref('basic')

// 学生用户数据
const userInfo = ref({
  name: '张三',
  studentId: '2023010101',
  gender: '男',
  department: '计算机科学与技术学院',
  major: '软件工程',
  className: '软工2301班',
  grade: '2023级',
  
  // 学籍信息
  enrollmentDate: '2023-09-01',
  schoolingLength: '4年',
  educationLevel: '本科',
  
  // 联系信息
  email: 'zhangsan@example.com',
  phone: '13812345678',
  emergencyContact: '13987654321'
})

// 组件挂载时初始化数据
onMounted(() => {
  console.log('Profile component mounted')
  console.log('User info:', userInfo.value)
})

// 敏感信息脱敏处理
const maskSensitiveInfo = (value) => {
  if (!value) return ''
  
  if (value.length <= 8) {
    // 短字符串处理
    return value.substring(0, 3) + '****' + value.substring(value.length - 1)
  } else if (value.length <= 11) {
    // 手机号处理
    return value.substring(0, 3) + '****' + value.substring(value.length - 4)
  } else {
    // 身份证号处理
    return value.substring(0, 6) + '********' + value.substring(value.length - 4)
  }
}
</script>

<style lang="scss" scoped>
.profile-container {
  padding: 0;
  
  // 顶部个人信息卡片样式
  .profile-banner {
    position: relative;
    height: 240px;
    border-radius: 8px;
    margin-bottom: 30px;
    overflow: hidden;
    transition: background-image 0.5s ease;
    
    &.student-banner {
      background-image: linear-gradient(120deg, #a1c4fd 0%, #c2e9fb 100%);
    }
    
    .banner-overlay {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: rgba(255, 255, 255, 0.1);
      backdrop-filter: blur(5px);
    }
    
    .profile-header {
      position: relative;
      height: 100%;
      display: flex;
      align-items: center;
      padding: 0 40px;
      z-index: 2;
      
      .profile-header-content {
        display: flex;
        align-items: center;
        width: 100%;
        
        .avatar-wrapper {
          margin-right: 40px;
          
          .avatar-container {
            position: relative;
            
            .user-avatar {
              border: 4px solid #fff;
              box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
            }
            
            .avatar-badge {
              position: absolute;
              bottom: 0;
              right: 0;
              padding: 4px 8px;
              border-radius: 12px;
              color: #fff;
              font-size: 12px;
              font-weight: bold;
              
              &.student-badge {
                background-color: #409EFF;
              }
            }
          }
        }
        
        .user-info {
          flex: 1;
          color: #fff;
          text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
          
          h1 {
            margin: 0 0 5px;
            font-size: 28px;
            font-weight: 600;
          }
          
          p {
            margin: 0 0 15px;
            font-size: 16px;
            opacity: 0.9;
          }
          
          .user-tags {
            display: flex;
            gap: 10px;
            
            .sync-badge {
              display: flex;
              align-items: center;
              
              .el-icon {
                margin-right: 5px;
              }
            }
          }
        }
      }
    }
  }
  
  // 内容区域样式
  .profile-tabs {
    margin-bottom: 30px;
    
    .custom-tabs {
      background-color: transparent;
      border: none;
      box-shadow: none;
      
      :deep(.el-tabs__header) {
        margin-bottom: 20px;
      }
      
      :deep(.el-tabs__nav-wrap::after) {
        height: 1px;
        background-color: #e4e7ed;
      }
      
      :deep(.el-tabs__item) {
        padding: 0 20px;
        height: 50px;
        line-height: 50px;
        transition: all 0.3s;
        
        &.is-active {
          color: #409EFF;
          font-weight: bold;
        }
        
        &:hover {
          color: #409EFF;
        }
      }
      
      .custom-tab-label {
        display: flex;
        align-items: center;
        
        .el-icon {
          margin-right: 8px;
          font-size: 18px;
        }
        
        span {
          font-size: 16px;
        }
      }
      
      .tab-content {
        padding: 10px;
        
        .info-card {
          border-radius: 8px;
          transition: all 0.3s;
          
          &:hover {
            transform: translateY(-5px);
          }
          
          .info-header {
            margin-bottom: 20px;
            border-bottom: 1px solid #ebeef5;
            padding-bottom: 15px;
            
            h3 {
              margin: 0 0 5px;
              font-size: 18px;
              color: #303133;
            }
            
            p {
              margin: 0;
              font-size: 14px;
              color: #909399;
            }
          }
          
          .info-extra {
            margin-top: 20px;
          }
        }
        
        .custom-descriptions {
          :deep(.el-descriptions__label) {
            width: 120px;
            text-align: right;
            padding-right: 20px;
            color: #606266;
            font-weight: bold;
          }
          
          :deep(.el-descriptions__content) {
            padding: 15px 20px;
          }
        }
      }
    }
  }
  
  // 底部操作区域样式
  .profile-actions {
    .action-card {
      border-radius: 8px;
      
      .action-header {
        margin-bottom: 20px;
        padding-bottom: 15px;
        border-bottom: 1px solid #ebeef5;
        
        h3 {
          margin: 0;
          font-size: 18px;
          color: #303133;
        }
      }
      
      .action-content {
        display: flex;
        flex-wrap: wrap;
        gap: 15px;
      }
    }
  }
  
  // 字段值样式
  .info-value {
    color: #303133;
    font-weight: 500;
  }
  
  .empty-value {
    color: #909399;
    font-style: italic;
  }
  
  .sensitive-field {
    display: flex;
    align-items: center;
    
    .sensitive-icon {
      margin-left: 8px;
      color: #E6A23C;
      font-size: 16px;
    }
  }
}

// 响应式样式
@media screen and (max-width: 768px) {
  .profile-container {
    .profile-banner {
      height: auto;
      padding: 20px 0;
      
      .profile-header {
        padding: 0 20px;
        
        .profile-header-content {
          flex-direction: column;
          text-align: center;
          
          .avatar-wrapper {
            margin-right: 0;
            margin-bottom: 20px;
          }
          
          .user-info {
            .user-tags {
              justify-content: center;
            }
          }
        }
      }
    }
    
    .profile-tabs {
      .custom-tabs {
        .tab-content {
          padding: 5px;
        }
      }
    }
    
    .profile-actions {
      .action-card {
        .action-content {
          flex-direction: column;
          
          .el-button {
            width: 100%;
          }
        }
      }
    }
  }
}
</style> 